package com.dalin.platform.loa.model;

import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import com.dalin.common.base.BaseObject;
import com.dalin.platform.loa.LoaConst;
import com.dalin.platform.loa.condition.LoaOperateCondition;
import com.dalin.platform.pub.PlatContext;

/*****************************************************************************
 * @content: 类信息                                                   *
 * @author : 那建林                                                                                                                                 *
 * @crtDate: 2010-05-11                                                     *
 * @modDate: 2010-05-11                                                     *
 * @version: 1.00                                                           *
 ****************************************************************************/
@Entity
@Table(name="LOA_MENU")
public class LoaMenuEntity extends BaseObject {
    private Long menuId; // MENU_ID,16,0
    private Long projectId; // PROJECT_ID,16,0
    private Integer menuType; // 用于哪类菜单,左侧树,或其他用途
    private Integer menuValue; // MENU_VALUE,8,0
    private String menuName; // MENU_NAME,64,0
    private String linkPath; // LINK_PATH,512,0
    private Integer sequence; // SEQUENCE,4,0
    private Long parentId; // PARENT_ID,16,0
    private String remark; // REMARK,256,0
    private Date createDate; // CREATE_DATE,7,0
    private Date modifyDate; // MODIFY_DATE,7,0
    private Integer valid; // VALID,2,0

    private Set<LoaRoleEntity> loaRoleEntitys = new HashSet<LoaRoleEntity>(0);



    @Id
    @Column(name="MENU_ID")
    @GeneratedValue(strategy = GenerationType.TABLE,generator="generator_normal")
    @TableGenerator(
        name = "generator_normal",
        table = "GLB_GENERATOR_KEY",
        pkColumnName = "GEN_KEY",
        valueColumnName = "GEN_VALUE",
        pkColumnValue = "LOA_MENU",
        allocationSize=1
    )
    public Long getMenuId() {
        return menuId;
    }

    public void setMenuId(Long menuId) {
        this.menuId = menuId;
    }

    @Column(name="PROJECT_ID")
    public Long getProjectId() {
        return projectId;
    }

    public void setProjectId(Long projectId) {
        this.projectId = projectId;
    }
    
    @Column(name="MENU_TYPE")
    public Integer getMenuType() {
		return menuType;
	}

	public void setMenuType(Integer menuType) {
		this.menuType = menuType;
	}

	@Column(name="MENU_VALUE")
    public Integer getMenuValue() {
        return menuValue;
    }

    public void setMenuValue(Integer menuValue) {
        this.menuValue = menuValue;
    }

    @Column(name="MENU_NAME")
    public String getMenuName() {
        return menuName;
    }

    public void setMenuName(String menuName) {
        this.menuName = menuName;
    }

    @Column(name="LINK_PATH")
    public String getLinkPath() {
        return linkPath;
    }

    public void setLinkPath(String linkPath) {
        this.linkPath = linkPath;
    }

    @Column(name="SEQUENCE")
    public Integer getSequence() {
        return sequence;
    }

    public void setSequence(Integer sequence) {
        this.sequence = sequence;
    }

    @Column(name="PARENT_ID")
    public Long getParentId() {
        return parentId;
    }

    public void setParentId(Long parentId) {
        this.parentId = parentId;
    }

    @Column(name="REMARK")
    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="CREATE_DATE")
    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="MODIFY_DATE")
    public Date getModifyDate() {
        return modifyDate;
    }

    public void setModifyDate(Date modifyDate) {
        this.modifyDate = modifyDate;
    }

    @Column(name="VALID")
    public Integer getValid() {
        return valid;
    }

    public void setValid(Integer valid) {
        this.valid = valid;
    }

    
    @ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.LAZY)
    @JoinTable(name = "LOA_ROLE_MENU", joinColumns = {
	        @JoinColumn(name = "MENU_ID")
	    }, inverseJoinColumns =  {
	        @JoinColumn(name = "ROLE_ID")
	    }
    )
    public Set<LoaRoleEntity> getLoaRoleEntitys() {
		return loaRoleEntitys;
	}

	public void setLoaRoleEntitys(Set<LoaRoleEntity> loaRoleEntitys) {
		this.loaRoleEntitys = loaRoleEntitys;
	}

	
	@Transient
	public List<LoaOperateEntity> getLoaOperateEntitys() {
		LoaOperateCondition cond = new LoaOperateCondition();
		cond.setMenuId(this.getMenuId());
		cond.setParentOperateId(Long.valueOf(LoaConst.BASE_PARENT_ID + ""));
		return PlatContext.getDao().queryObjsToPages(cond.prepareParams()
				.getPreparedPageQuery());
	}
	
	
	
	
	
	
	
	
	
	
    @Override
    public int hashCode() {
        int njlrst = 17;
        njlrst = 31 * njlrst + (menuId == null ? 0 : menuId.hashCode());
        njlrst = 31 * njlrst + (projectId == null ? 0 : projectId.hashCode());
        njlrst = 31 * njlrst + (menuValue == null ? 0 : menuValue.hashCode());
        njlrst = 31 * njlrst + (menuName == null ? 0 : menuName.hashCode());
        njlrst = 31 * njlrst + (linkPath == null ? 0 : linkPath.hashCode());
        njlrst = 31 * njlrst + (sequence == null ? 0 : sequence.hashCode());
        njlrst = 31 * njlrst + (parentId == null ? 0 : parentId.hashCode());
        njlrst = 31 * njlrst + (remark == null ? 0 : remark.hashCode());
        njlrst = 31 * njlrst + (createDate == null ? 0 : createDate.hashCode());
        njlrst = 31 * njlrst + (modifyDate == null ? 0 : modifyDate.hashCode());
        njlrst = 31 * njlrst + (valid == null ? 0 : valid.hashCode());
        njlrst = 31 * njlrst + (loaRoleEntitys == null ? 0 : loaRoleEntitys.hashCode());
        return njlrst;
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof LoaMenuEntity)) return false;
        final LoaMenuEntity other = (LoaMenuEntity) o;
        if (menuId == null) {
            if (other.menuId != null) return false;
        } else if (!menuId.equals(other.menuId)) {
            return false;
        }
        if (projectId == null) {
            if (other.projectId != null) return false;
        } else if (!projectId.equals(other.projectId)) {
            return false;
        }
        if (menuValue == null) {
            if (other.menuValue != null) return false;
        } else if (!menuValue.equals(other.menuValue)) {
            return false;
        }
        if (menuName == null) {
            if (other.menuName != null) return false;
        } else if (!menuName.equals(other.menuName)) {
            return false;
        }
        if (linkPath == null) {
            if (other.linkPath != null) return false;
        } else if (!linkPath.equals(other.linkPath)) {
            return false;
        }
        if (sequence == null) {
            if (other.sequence != null) return false;
        } else if (!sequence.equals(other.sequence)) {
            return false;
        }
        if (parentId == null) {
            if (other.parentId != null) return false;
        } else if (!parentId.equals(other.parentId)) {
            return false;
        }
        if (remark == null) {
            if (other.remark != null) return false;
        } else if (!remark.equals(other.remark)) {
            return false;
        }
        if (createDate == null) {
            if (other.createDate != null) return false;
        } else if (!createDate.equals(other.createDate)) {
            return false;
        }
        if (modifyDate == null) {
            if (other.modifyDate != null) return false;
        } else if (!modifyDate.equals(other.modifyDate)) {
            return false;
        }
        if (valid == null) {
            if (other.valid != null) return false;
        } else if (!valid.equals(other.valid)) {
            return false;
        }
        if (loaRoleEntitys == null) {
            if (other.loaRoleEntitys != null) return false;
        } else if (!loaRoleEntitys.equals(other.loaRoleEntitys)) {
            return false;
        }
        return true;
    }
}